<?php
/*********************/
/*                   */
/*  后台会员积分模块       */
/*   BY voiet        */
/*   2009-9-15更新    */
/*                   */
/*********************/
//require_once( CORE_DIR."/model/trading/mdl.memberpoint.php" );
class cmd_memberpoint extends mdl_memberpoint
{
	function adminchgpoint( $userId, $nPoint, $sReason, $sDescribe, $relatedId = null, $opname )
	{
			if ( $nPoint == 0 )
			{
					return true;
			}
			if ( !$this->_chgpoint( $userId, $nPoint ) )
			{
						trigger_error( __( "积分扣除超过会员已有积分" ), E_USER_ERROR );
						return false;
			}
			//$oMember = $this->system->loadmodel( "member/member" );
			//$aPoint = $oMember->getfieldbyid( $userId, array( "point" ) );
			//$oLv = $this->system->loadmodel( "member/level" );
			if ( $userId )
			{
					$userId = intval( $userId );
					$oPointHistory = $this->system->loadmodel( "trading/pointHistory" );
					$aUserPoint['point'] = $this->getmemberpoint( $userId );
					$aUserPoint['point'] += $nPoint;
					$rRs = $this->db->query( "select * from sdb_members where member_id=".$userId );
					$sSql = $this->db->getupdatesql( $rRs, $aUserPoint );
					if ( $sSql )
					{
								$this->db->exec( $sSql );
					}
					
					//$aHistoryReason = $oPointHistory->gethistoryreason( );
					//$this->toupdatelevel( $userId );
					$aPointHistory = array(
									"member_id" => $userId,
									"point" => $nPoint,
									"reason" => $sReason,
									"related_id" => $relatedId,
									"describe" =>$sDescribe,
									"operator" => $opname
							);
					$oPointHistory->addhistory( $aPointHistory );
					
			return true;		
			}
			else {
				trigger_error( __( "积分历史添加不成功" ), E_USER_ERROR );
				return false;
			}
			
		}
		
		
	function chgpointall( $userId, $nPoint, $sReason, $relatedId = null )
	{
		if ( $nPoint == 0 )
		{
			return true;
		}
		if ( !$this->_chgpoint( $userId, $nPoint ) )
		{
			trigger_error( __( "积分扣除超过会员已有积分" ), E_USER_ERROR );
			return false;
		}
		//$oMember = $this->system->loadmodel( "member/member" );
		//$aPoint = $oMember->getfieldbyid( $userId, array( "point" ) );
		//$oLv = $this->system->loadmodel( "member/level" );
		if ( $userId )
		{
			$userId = intval( $userId );
			$oPointHistory = $this->system->loadmodel( "trading/pointHistory" );
			$aUserPoint['point'] = $this->getmemberpoint( $userId );
			$aUserPoint['point'] += $nPoint;
			$rRs = $this->db->query( "select * from sdb_members where member_id=".$userId );
			$sSql = $this->db->getupdatesql( $rRs, $aUserPoint );
			if ( $sSql )
			{
				$this->db->exec( $sSql );
			}
			//$this->toupdatelevel( $userId );
			$aPointHistory = array(
				"member_id" => $userId,
				"point" => $nPoint,
				"reason" => $sReason,
				"related_id" => $relatedId
			);
			$oPointHistory->addhistory( $aPointHistory );
		}
		return true;
	}

}

?>